package to3;

import java.awt.Color;
import java.io.*;
import java.util.*;
import java.awt.Dimension;
import java.awt.Toolkit;

public class AccountToevoegen extends javax.swing.JFrame {
    private KlantenLijst k1;
    
    public AccountToevoegen() {
        initComponents();
        k1 = new KlantenLijst();
        setVisible(true);
//        try {
//            readFile();
//        } catch (IOException ex) {
//            ex.printStackTrace();
//        }
        errorLabel.setVisible(false);
                ////////SCHERM IN MIDDEN////////
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension windowSize = this.getSize();

        int windowX = Math.max(0, (screenSize.width  - windowSize.width ) / 2);
        int windowY = Math.max(0, (screenSize.height - windowSize.height) / 2);

        this.setLocation(windowX, windowY);
        ///////////////////////////////
        
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDesktopPane1 = new javax.swing.JDesktopPane();
        voornaamTF = new javax.swing.JTextField();
        achternaamTF = new javax.swing.JTextField();
        adresTF = new javax.swing.JTextField();
        woonplaatsTF = new javax.swing.JTextField();
        telefoonTF = new javax.swing.JTextField();
        emailTF = new javax.swing.JTextField();
        rekeningTF = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        errorLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Klantaccount openen");
        setBounds(new java.awt.Rectangle(0, 0, 800, 600));
        setMaximizedBounds(new java.awt.Rectangle(0, 0, 800, 600));
        setMinimumSize(new java.awt.Dimension(800, 600));
        setResizable(false);

        voornaamTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                voornaamTFActionPerformed(evt);
            }
        });

        achternaamTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                achternaamTFActionPerformed(evt);
            }
        });

        adresTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adresTFActionPerformed(evt);
            }
        });

        emailTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                emailTFActionPerformed(evt);
            }
        });

        rekeningTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rekeningTFActionPerformed(evt);
            }
        });

        jLabel7.setText("Rekeningnummer:");

        jLabel6.setText("E-mailadres:");

        jLabel8.setText("Telefoonnummer:");

        jLabel5.setText("Woonplaats:");

        jLabel4.setText("Adres:");

        jLabel3.setText("Achternaam:");

        jLabel2.setText("Voornaam:");

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel1.setText("Klantaccount openen");

        jButton1.setText("Voeg toe");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Hoofdmenu");
        jButton2.setPreferredSize(new java.awt.Dimension(164, 46));
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        errorLabel.setForeground(new java.awt.Color(255, 0, 0));
        errorLabel.setText("Een of meerdere velden zijn niet ingevuld.");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(636, Short.MAX_VALUE)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(209, 209, 209)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(woonplaatsTF)
                                    .addComponent(achternaamTF)
                                    .addComponent(adresTF)
                                    .addComponent(telefoonTF)
                                    .addComponent(emailTF)
                                    .addComponent(rekeningTF)
                                    .addComponent(voornaamTF, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(289, 289, 289)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(errorLabel)
                                    .addComponent(jLabel1))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 240, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 469, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(256, 256, 256))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(errorLabel)
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(voornaamTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(achternaamTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(adresTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(woonplaatsTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(telefoonTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(emailTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rekeningTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 205, Short.MAX_VALUE)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

//private void writeKlanten() throws IOException{
//          List<Klant> listP = k1.getKlanten();
//          FileWriter fw	 = new FileWriter("klanten.txt");
//                PrintWriter pw	 = new PrintWriter(fw);
//                boolean eersteKeer = false;
//  		for (Klant kl : listP){
//                if(eersteKeer == false){
//                    pw.print(kl.getKlantnr() + ", " + kl.getVoornaam() + ", " + kl.getAchternaam() + ", " +kl.getAdres() + ", "
//                                             + kl.getWoonplaats() + ", " + kl.getTelefoon() + ", " + kl.getEmail() + ", " 
//                                             + kl.getRekeningnr());
//                    eersteKeer = true;
//                                        }
//                    else{
//                        pw.print("\n" + kl.getKlantnr() + ", " + kl.getVoornaam() + ", " + kl.getAchternaam() + ", " +kl.getAdres() + ", "
//                                                        + kl.getWoonplaats() + ", " + kl.getTelefoon() + ", " + kl.getEmail() + ", " 
//                                                        + kl.getRekeningnr());
//                        }
//                }
//  		pw.close();
//                fw.close();
//    }    
// 
//    private void readFile() throws IOException {
//                k1.clearKlantenLijst();
//		FileReader fr = new FileReader("klanten.txt");
//                BufferedReader br = new BufferedReader(fr);
//
//                    while (true) {
//                    String regel = br.readLine();
//                    if (regel == null) {
//                    break;
//                    }
//                    Scanner sc = new Scanner(regel);
//                    sc.useDelimiter("\\s*,\\s*");
//                    String klantnr = sc.next();
//                    String voornaam = sc.next();
//                    String achternaam = sc.next();
//                    String adres = sc.next();
//                    String woonplaats = sc.next();
//                    String telefoon = sc.next();
//                    String email = sc.next();
//                    String rekeningnr = sc.next();
//                    k1.addKlant(klantnr, voornaam, achternaam, adres, woonplaats, telefoon, email, rekeningnr);
//                    
//                    sc.close();
//                    }
//        }
    
    
    private void voornaamTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_voornaamTFActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_voornaamTFActionPerformed

    private void achternaamTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_achternaamTFActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_achternaamTFActionPerformed

    private void emailTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_emailTFActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_emailTFActionPerformed

    private void rekeningTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rekeningTFActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rekeningTFActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        boolean error = false;
        //kijk of de tekstvelden niet leeg zijn.
        if((voornaamTF.getText().equals(""))){
            voornaamTF.setBackground(Color.red);
            error = true;  
        }   else {
            voornaamTF.setBackground(Color.white);
        }
        
        if((woonplaatsTF.getText().equals(""))){
            woonplaatsTF.setBackground(Color.red);
            error = true;
        }    else {
            woonplaatsTF.setBackground(Color.white);
        }
        
        if((achternaamTF.getText().equals(""))){
            achternaamTF.setBackground(Color.red);
            error = true;
        }    else {
            achternaamTF.setBackground(Color.white);
        }
        
        if((adresTF.getText().equals(""))){
            adresTF.setBackground(Color.red);
            error = true;
        }    else {
            adresTF.setBackground(Color.white);
        }
        
        if((telefoonTF.getText().equals(""))){
            telefoonTF.setBackground(Color.red);
            error = true;
        }    else {
            telefoonTF.setBackground(Color.white);
        }
        
        if((emailTF.getText().equals(""))){
            emailTF.setBackground(Color.red);
            error = true;
        }    else {
            emailTF.setBackground(Color.white);
        }
        
        if((rekeningTF.getText().equals(""))){
            rekeningTF.setBackground(Color.red);
            error = true;
        }    else {
            rekeningTF.setBackground(Color.white);
        }
        
        if(error){
            errorLabel.setVisible(true);
        }else{
             errorLabel.setVisible(false);
             k1.addNewKlant(voornaamTF.getText(), achternaamTF.getText(), 
                    adresTF.getText(), woonplaatsTF.getText(), 
                    telefoonTF.getText(), emailTF.getText(),
                    rekeningTF.getText());
//            try {
//                writeKlanten();
//            } catch (IOException ex) {
//                ex.printStackTrace();
//            }
            voornaamTF.setText("");
            woonplaatsTF.setText("");
            achternaamTF.setText("");
            adresTF.setText("");
            telefoonTF.setText("");
            emailTF.setText("");
            rekeningTF.setText("");

        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        hoofdMenu hM = new hoofdMenu();
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void adresTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adresTFActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_adresTFActionPerformed

    public static void main(String args[]) {

       //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AccountToevoegen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AccountToevoegen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AccountToevoegen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AccountToevoegen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new AccountToevoegen().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField achternaamTF;
    private javax.swing.JTextField adresTF;
    private javax.swing.JTextField emailTF;
    private javax.swing.JLabel errorLabel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JTextField rekeningTF;
    private javax.swing.JTextField telefoonTF;
    private javax.swing.JTextField voornaamTF;
    private javax.swing.JTextField woonplaatsTF;
    // End of variables declaration//GEN-END:variables
}